﻿using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.ComponentModel;

namespace MyFloridaHouse.libSvUIControls
{
    public class ColorScaleSection : INotifyPropertyChanged
    {

        #region propertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion

        public ColorScaleSection(SolidColorBrush sectionBackground, int sectionWidth, int percent) 
        {
            colorSectionBackground = sectionBackground;
            colorSectionWidth = sectionWidth;
            colorPercent = percent;
        }

        private SolidColorBrush _colorSectionBackground;
        public SolidColorBrush colorSectionBackground
        {
            get
            {
                return _colorSectionBackground;
            }

            set
            {
                if (_colorSectionBackground != value)
                {
                    _colorSectionBackground = value;
                    NotifyPropertyChanged("colorSectionBackground");
                }
            }
        }

        private int _colorSectionWidth;
        public int colorSectionWidth
        {
            get
            {
                return _colorSectionWidth;
            }

            set
            {
                if (_colorSectionWidth != value)
                {
                    _colorSectionWidth = value;
                    NotifyPropertyChanged("colorSectionWidth");
                }
            }
        }

        private int _colorPercent;
        public int colorPercent
        {
            get
            {
                return _colorPercent;
            }

            set
            {
                if (_colorPercent != value)
                {
                    _colorPercent = value;
                    NotifyPropertyChanged("colorPercent");
                }
            }
        }
    }

    public partial class ColorScale : UserControl
    {
        public ColorScale()
        {
            InitializeComponent();
            //this.Loaded += new RoutedEventHandler(ColorScale_Loaded);
            LayoutRoot.DataContext = this;

        }

        void ColorScale_Loaded(object sender, RoutedEventArgs e)
        {
            // wire up mouseOver event for color chooser
        }

        #region dependency properties

        public int ColorPercent
        {
            get { return (int)GetValue(ColorScale.ColorPercentProperty); }
            set { SetValue(ColorScale.ColorPercentProperty, value); }
        }

        public static readonly DependencyProperty ColorPercentProperty =
            DependencyProperty.Register("ColorPercentProperty", typeof(int), typeof(ColorScale), new PropertyMetadata(0));

        public SolidColorBrush MinBackground
        {
            get { return (SolidColorBrush)GetValue(ColorScale.MinBackgroundProperty); }
            set { SetValue(ColorScale.MinBackgroundProperty, value); }
        }

        public static readonly DependencyProperty MinBackgroundProperty =
            DependencyProperty.Register("MinBackground", typeof(SolidColorBrush), typeof(ColorScale), new PropertyMetadata(new SolidColorBrush(Colors.Green)));

        public SolidColorBrush MaxBackground
        {
            get { return (SolidColorBrush)GetValue(MaxBackgroundProperty); }
            set { SetValue(MaxBackgroundProperty, value); }
        }

        public static readonly DependencyProperty MaxBackgroundProperty =
            DependencyProperty.Register("MaxBackground", typeof(SolidColorBrush), typeof(ColorScale), new PropertyMetadata(new SolidColorBrush(Colors.Cyan)));

        public ObservableCollection<ColorScaleSection> ColorScaleSectionList
        {
            get { return (ObservableCollection<ColorScaleSection>)GetValue(ColorScaleSectionListProperty); }
            set { SetValue(ColorScaleSectionListProperty, value); }
        }

        public static readonly DependencyProperty ColorScaleSectionListProperty =
            DependencyProperty.Register("ColorScaleSection", typeof(ObservableCollection<ColorScaleSection>), typeof(ColorScale), new PropertyMetadata(new ObservableCollection<ColorScaleSection>()));


        public int ColorSectionWidth
        {
            get { return (int)GetValue(ColorScale.ColorSectionWidthProperty); }
            set { SetValue(ColorScale.ColorSectionWidthProperty, value); }
        }

        public static readonly DependencyProperty ColorSectionWidthProperty =
            DependencyProperty.Register("ColorSectionWidth", typeof(int), typeof(ColorScale), new PropertyMetadata(5));

        #endregion

    }
}
